<template>
  <view class="cart-page" v-if="cart.length !== 0">
    <MyAddress></MyAddress>
    <view class="cart-title">
      <uni-icons type="shop" size="22"></uni-icons>
      <text>购物车</text>
    </view>
    <view class="cart-content">
      <uni-swipe-action>
        <block v-for="item in cart" :key="item.goods_id">
          <uni-swipe-action-item :right-options="rightOptions" @click="handleClick(item, $event)">
            <MyCartItem :item="item"></MyCartItem>
          </uni-swipe-action-item>
        </block>
      </uni-swipe-action>
      
    </view>
    <MySettlement></MySettlement>
  </view>
  <view class="blank-page" v-else>
    <image src="../../static/cart_empty@2x.png"></image>
    <text>空空如也~</text>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        rightOptions: [{
          text: '删除',
          style: {
            backgroundColor: '#c00000'
          }
        }]
      };
    },
    computed: {
      info() {
        return this.$store.getters.info
      },
      cart() {
        return this.$store.state.cart.cart
      }
    },
    methods: {
      handleClick(item, e) {
        this.$store.dispatch('delToCart', item)
      }
    },
    onShow() {
      uni.setTabBarBadge({
        index: 2,
        text: `${this.info}`
      })
    }
  }
</script>

<style lang="scss" scoped>
  .cart-page {
    position: relative;
    padding-bottom: 100rpx;
    .cart-title {
      display: flex;
      align-items: center;
      padding-left: 20rpx;
      height: 80rpx;
      background-color: white;
      border-bottom: 1px solid lightgray;

      text {
        margin-left: 10rpx;
      }
    }

    .cart-content {}
  }
  .blank-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 200rpx;
    image {
      width: 200rpx;
      height: 200rpx;
    }
    text {
      margin-top: 30rpx;
      color: gray;
      font-size: 28rpx;
    }
  }
</style>